var pageii = null;
var grid = null;

$(function () {
    grid = lyGrid({
        pagId: 'paging',
        l_column: [{
            colkey: 'cfg_grp',
            name: '分组'
        }, {
            colkey: 'cfg_key',
            name: '键'
        }, {
            colkey: 'cfg_desc',
            name: '描述'
        }, {
            colkey: 'cfg_val',
            name: '值'
        }],
        jsonUrl: rootPath + '/sys/config/findByPage.shtml',
        dymCol: true,
        checkbox: true,
        serNumber: true
    });
    $('#search').click('click', function () { // 绑定查询按扭
        var searchParams = $('#searchForm').serializeJson(); // 初始化传参数
        grid.setOptions({
            data: searchParams
        });
    });

    $("#addFun").click("click", function () {
        addFun();
    });
    $("#editFun").click("click", function () {
        editFun();
    });
    $("#delFun").click("click", function () {
        delFun();
    });
});

function editFun() {
    var cbox = grid.getSelectedCheckbox();
    if (cbox.length > 1 || cbox == "") {
        layer.msg("只能选中一个");
        return;
    }
    pageii = layer.open({
        title: "编辑",
        type: 2,
        area: ["600px", "80%"],
        content: rootPath + '/sys/config/editUI.shtml?id=' + cbox
    });
}

function addFun() {
    pageii = layer.open({
        title: "新增",
        type: 2,
        area: ["600px", "80%"],
        content: rootPath + '/sys/config/addUI.shtml'
    });
}

function delFun() {
    var cbox = grid.getSelectedCheckbox();
    if (cbox == "") {
        layer.msg("请选择删除项！！");
        return;
    }
    layer.confirm('是否删除？', function (index) {
        var url = rootPath + '/sys/config/deleteEntity.shtml';
        var s = CommnUtil.ajax(url, {
            ids: cbox.join(",")
        }, "json");
        if (s == "success") {
            layer.msg('删除成功');
            grid.loadData();
        } else {
            layer.msg('删除失败');
        }
    });
}
